﻿//var http = "https://localhost:44358";
var http = GetWebHost();
var s = "cgi";
var version = "v1";
var uuid = "ca5df1852eb1478a913fc6d5fbbdc7a0";
var serviceUrl = http + "/" + s + "/" + version;

var sysConfigPath = "sys/config/get";
var logVisitorRecordPath = "log/visitor/record";
var institutionCompanyPath = "institution/company/get";
var homeIndexPath = "home/index";
var infoClassPath = "info/class";
var infoPagePath = "info/page/get";
var infoArticePath = "info/artice";
var serviceMessageBoard = "service/message/board";

function createSysConfigUrl() {
    return serviceUrl + "/" + sysConfigPath + "?uuid=" + uuid;
}
function createLogVisitorRecordUrl(path) {
    return serviceUrl + "/" + logVisitorRecordPath + "/" + path + "?uuid=" + uuid;
}
function createInstitutionCompanyUrl() {
    return serviceUrl + "/" + institutionCompanyPath + "?uuid=" + uuid;
}
function createHomeIndexUrl() {
    return serviceUrl + "/" + homeIndexPath + "?uuid=" + uuid;
}
function createInfoClassUrl(path) {
    return serviceUrl + "/" + infoClassPath + "/" + path + "?uuid=" + uuid;
}
function createInfoPageUrl(id) {
    return serviceUrl + "/" + infoPagePath + "?uuid=" + uuid + "&classid=" + id;
}
function createInfoArticeUrl(path) {
    return serviceUrl + "/" + infoArticePath + "/" + path + "?uuid=" + uuid;
}
function createServiceMessageBoardUrl(path) {
    return serviceUrl + "/" + serviceMessageBoard + "/" + path + "?uuid=" + uuid;
}

//转义内容
function HTMLEncode(html) {
    var temp = document.createElement("div");
    (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
    var output = temp.innerHTML;
    temp = null;
    return output;
}
//反转内容
function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
} 
//获取url参数
function getQueryString(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) { return pair[1]; }
    }
    return (false);
}
//'yyyy-MM-dd HH:mm:ss'格式的字符串转日期
function stringToDate(str) {
    var tempStrs = str.split(" ");
    var dateStrs = tempStrs[0].split("-");
    var year = parseInt(dateStrs[0], 10);
    var month = parseInt(dateStrs[1], 10) - 1;
    var day = parseInt(dateStrs[2], 10);
    var timeStrs = tempStrs[1].split(":");
    var hour = parseInt(timeStrs[0], 10);
    var minute = parseInt(timeStrs[1], 10);
    var second = parseInt(timeStrs[2], 10);
    var date = new Date(year, month, day, hour, minute, second);
    return date;
}
//获取url host
function GetWebHost() {
    var protocol = window.location.protocol;
    var host = window.location.host;
    return protocol + "//" + host;
}

//计算总页数
function getTotalPageNum(size, total) {
    return (total + size - 1) / size;
}
//js分页页码算法
function getPagingHtml(page, total) {
    var result = "";
    var totalPage = getTotalPageNum(9, total)
    if (page > 1) {
        result += `<a href="?classid=${classid}&page=1" class="next">上一页</a>`;
    }
    for (var i = 1; i <= totalPage; i++) {
        if (i == 2 && page - 6 > 1) {
            i = page - 6;
        } else if (i == page + 6 && page + 6 < totalPage) {
            i = totalPage - 1;
        } else {
            if (i == page) {
                result += `<a href="?classid=${classid}&page=${i}" class="curr">${i}</a>`;
            } else {
                result += `<a href="?classid=${classid}&page=${i}">${i}</a>`;
            }
        }
    }
    if (page < parseInt(totalPage)) {
        result += `<a href="?classid=${classid}&page=${page + 1}" class="next">下一页</a>`;
    }
    return result;
} 

